import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:im_app/demo/page/CameraSamplePage.dart';
import 'package:im_app/demo/page/EasyRefreshCubit.dart';
import 'package:im_app/demo/page/EasyRefreshPage.dart';
import 'package:im_app/demo/page/LoadMoreCubit.dart';
import 'package:im_app/demo/page/LoadMoreCubitPage.dart';
import 'package:im_app/demo/page/LoadMorePage.dart';
import 'package:im_app/demo/page/LoopBackSampleWithGetStats.dart';
import 'package:im_app/demo/page/PullRefreshCubit.dart';
import 'package:im_app/demo/page/PullRefreshPage.dart';
import 'package:im_app/demo/page/SupListDemo.dart';
import 'package:im_app/demo/page/SupListDemo2.dart';
import 'package:im_app/demo/page/footer_underscroll.dart';

import 'MainDemo.dart';
import 'page/OverlayDemo.dart';

typedef ItemFunction = Widget Function(BuildContext context);

class DemoPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _buildAppbar(context),
      body: _buildBody(context),
    );
  }

  AppBar _buildAppbar(BuildContext context) {
    return AppBar(
        leading: GestureDetector(
            child: const Padding(
              padding: EdgeInsets.only(left: 0, right: 0),
              child: Icon(Icons.chevron_left),
            ),
            onTap: () {
              Navigator.of(context).pop();
            }),
        titleSpacing: 5,
        title: const Text('DEMO',));
  }

  Widget _buildBody(BuildContext context) {
    return ListView(children: [
      _buildItem('IndexPage', context, (context)=> const IndexPage()),
      _buildItem('SupListPage', context, (context)=> SupListPage()),
      _buildItem('SupListPage2', context, (context)=> SupListPage2()),
      _buildItem('WebRtcDemo', context, (context)=> LoopBackSampleWithGetStats()),
      _buildItem('CameraSample', context, (context)=> CameraSamplePage()),
      _buildItem('PullRefresh', context, (context)=> BlocProvider(create: (context)=> PullRefreshCubit(), child: PullRefreshPage(),)),
      _buildItem('FooterUnderScroll', context, (context)=> FooterUnderScroll()),
      _buildItem('LoadMore', context, (context)=> LoadMorePage(title: 'load more demo')),
      _buildItem('LoadMoreCubit', context, (context)=> BlocProvider(create: (context)=> LoadMoreCubit(), child: LoadMoreCubitPage(title: 'load more cubit demo'),)),
      _buildItem('EasyRefresh', context, (context)=> BlocProvider(create: (context)=> EasyRefreshCubit(context), child: EasyRefreshPage(),)),
      _buildItem('OverlayDemo', context, (context)=> OverlayDemo()),
    ],);
  }

  Widget _buildItem(String title, BuildContext context, ItemFunction itemFunction) {
    return ListTile(title: Text(title), onTap: ()=> {
      Navigator.of(context).push(MaterialPageRoute(builder: (context)=> itemFunction(context))),
    });
  }
}
